package com.linjiahao.nettyOne.handler.Impl;

import com.alibaba.fastjson.JSON;
import com.linjiahao.nettyOne.constant.HandlerServiceName;
import com.linjiahao.nettyOne.domain.ChatMessage;
import com.linjiahao.nettyOne.handler.AbstractHandle;
import com.linjiahao.nettyOne.handler.ChannelHandlerPool;
import com.linjiahao.nettyOne.handler.HandlerServiceFactory;
import com.linjiahao.nettyOne.server.SendMessage;
import com.linjiahao.servicebase.common.RabbitPublisher;
import com.linjiahao.servicebase.common.RedisService;
import com.linjiahao.servicebase.vo.NettyMessageVO;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelId;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.net.UnknownHostException;
import java.util.UUID;

/**
 * @ClassName AddFriendHandlerImpl
 * @Description: 添加好友消息推送
 * @Author linjiahao
 * @Date 6/1/2022
 **/
@Service
@Slf4j
public class AddFriendHandlerImpl implements AbstractHandle, InitializingBean {

    @Resource
    private SendMessage sendMessage;

    @Override
    public String getServiceTypeName() {
        return HandlerServiceName.ADD_FRIEND.getName();
    }

    @Override
    public Object handlerWebsocket(ChannelHandlerContext ctx, Object message) throws UnknownHostException {
        NettyMessageVO nettyMessageVO = (NettyMessageVO)message;
        log.info("添加好友消息发送：发送者userId：{}，接收者userId：{}",nettyMessageVO.getUserId(),nettyMessageVO.getReceiveId());
        sendMessage.send(ctx,nettyMessageVO,Boolean.FALSE);
        return null;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        HandlerServiceFactory.register(getServiceTypeName(),this);
    }
}
